package com.gimi.cloud.mmf.user.dao;

import java.util.List;
import java.util.Map;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.gimi.cloud.mmf.user.config.jpa.BaseRepository;
import com.gimi.cloud.mmf.user.entity.TestUser;

public interface TestUserDao extends BaseRepository<TestUser, Long>{
	
	/**
	 *hql查询
	 * @param userName
	 * @param pageable
	 * @return
	 */
	@Query("select t from TestUser t where userName=:userName")
	List<TestUser> queryByHql(@Param("userName") String userName, Pageable pageable);

	/**
	 * sql查询
	 * @param userName
	 * @param pageable
	 * @return
	 */
	@Query(value = "select * from test_user where user_name=:userName", nativeQuery = true)
	List<TestUser> queryBySql(@Param("userName")String userName);

	/**
	 * 方法名查询
	 * @param userName
	 * @param pageable
	 * @return
	 */
	List<TestUser> findByUserName(String userName, Pageable pageable);

	/**
	 * hql链表
	 * @param userName
	 * @param pageable
	 * @return
	 */
	@Query("select new map(t.id as id, tc.money as money) from TestUser t join t.testCapitalLogs tc where t.userName = :userName")
	List<Map<String, Object>> queryMoreTableByHql(@Param("userName") String userName, Pageable pageable);

}
